var app = getApp();
import {
  getOrderByState,
  updateOrderState
} from "../../api/order.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navTab: [{
        id: "3",
        name: '全部订单'
      },
      {
        id: "0",
        name: '待拣货'
      },
      {
        id: "1",
        name: '待取货'
      },
      {
        id: "2",
        name: '以完成'
      }

    ],
    currentTab: 0,
    form: [],
    sendList: [],
  },
  select: {
    page: 1,
    size: 6,
    isEnd: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  load(e) {
    var that = this
    getOrderByState(e).then(res => {
      that.setData({
        form: res.data
      })
    })
  },
  onLoad: function (options) {
    let state = {
      state: '3'
    }
    this.load(state)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // this.getData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  handleClick(e) {
    let data = e.currentTarget.dataset.item
    data.state = '2'
    data.overTime =
      new Date().toJSON().substring(0, 10) + ' ' + new Date().toTimeString().substring(0, 8)
    updateOrderState(data).then(res => {
      console.log(res); 
      wx.showToast({
        title: "取货成功",
        icon: 'none',
        duration: 2000
      })
      let state = {
        state: '1'
      }
      this.load(state)
    })
  },
  currentTab: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.id
    })
    let state = {
      state: e.currentTarget.dataset.id
    }
    var that = this
    getOrderByState(state).then(res => {
      if (res.code == '200') {
        that.setData({
          form: res.data
        })
      }
    })
  },

})